package com.aqarat.managedBean;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

import com.aqarat.controller.AqaratController;
import com.aqarat.controller.AqaratControllerImpl;
import com.aqarat.entity.Building;
import com.aqarat.entity.Customer;
import com.aqarat.entity.Expens;
import com.core.managedBean.BaseBean;

@ManagedBean
@ViewScoped
public class ExpensesSearchBean extends BaseBean {

	private static final long serialVersionUID = 1L;
	private AqaratController aqaratController;
	private Expens expens;
	private List<Building> buildingList;
	
	LazyDataModel<Expens> lazyLoad = new LazyDataModel<Expens>() {
		@Override
		public List<Expens> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
			lazyLoad.setRowCount(aqaratController.getExpensListRowCount(expens).intValue());
			return aqaratController.getExpensList(first, pageSize, sortField, sortOrder, filters, expens);
		}
	};

	@PostConstruct
	public void loadData() {
		if (aqaratController == null) {
			aqaratController = new AqaratControllerImpl();
		}
		if (expens == null) {
			expens = new Expens();
		}
		loadBuildingList();		
	}

	public void loadBuildingList() {
		buildingList=aqaratController.getBuildingLookupList();
	}
	public void searchExpenses(){
		try {
			getExpensList();
		} catch (Exception e) {
			super.addErrorMessage("An Error Occured");
			e.printStackTrace();
		}
	}
	// --------------------------------------------------------------
	public LazyDataModel<Expens> getExpensList() {
		return lazyLoad;
	}
	public final Expens getExpens() {
		return expens;
	}

	public final void setExpens(Expens expens) {
		this.expens = expens;
	}

	public final LazyDataModel<Expens> getLazyLoad() {
		return lazyLoad;
	}

	public final void setLazyLoad(LazyDataModel<Expens> lazyLoad) {
		this.lazyLoad = lazyLoad;
	}

	public void setBuildingList(List<Building> buildingList) {
		this.buildingList = buildingList;
	}

	public List<Building> getBuildingList() {
		return buildingList;
	}

}
